home *** CD-ROM | disk | FTP | other *** search
- /* LIGHTS.KB
- Simple diagnosis of a faulty series circuit.
- After loading this file (using ?- kb 'lights.kb'.)
- you invoke the forward-chainer via
- ?- fc.
-
- N.B. to make the demo work, you must answer
- that chain_of_lights1 is the problematic device.
- That is, when you see the prompt
- Please name the problematic device==>
- you should type in
- chain_of_lights1.
- BE SURE TO INCLUDE THE 'FULL STOP' (PERIOD)
- */
-
- /* Static causal model for connected devices */
-
- chain_of_lights1 instance_of series_circuit with
- components: [bulb1, bulb2, bulb3, plug1, fuse1],
- last_element: bulb3.
-
- bulb1 instance_of bulb with
- comes_from: plug1,
- goes_to: bulb2.
-
- bulb2 instance_of bulb with
- comes_from: bulb1,
- goes_to: bulb3.
-
- bulb3 instance_of bulb with
- comes_from: bulb2.
-
- plug1 instance_of plug with
- comes_from: fuse1,
- goes_to: bulb1.
-
- fuse1 instance_of fuse with
- comes_from: mains,
- goes_to: plug1.
-
- /* some explained_by clauses in case of "why." responses to queries */
-
- ['Please name the problematic device']
- explained_by
- ['The name of the device is used as a starting point, from which we',nl,
- 'look up its sub-parts and then start searching for the weak link.',nl].
-
- ['Test ',Item,'in a known working circuit',nl,
- 'and then enter "ok." if it works,',nl,
- 'or "kaput." if it does not.']
- explained_by
- ['We use this information to identify the weak link in the chain.'].
-
- /* The rules for "no chain is stronger than its weakest link" */
-
- rule init forward
- if
- start
- then
- remove start &
- query ['Please name the problematic device'] receives_answer D &
- add [D,is,broken].
-
- rule begin_chaining forward
- if
- [D,is,broken] &
- D instance_of series_circuit &
- the last_element of D is Last
- then
- add [follow,the,chain,from,Last].
-
- rule continue_chaining forward
- if
- [follow,the,chain,from,Item] &
- [Item,is,ok] &
- the comes_from of Item is PreviousItem
- then
- remove [follow,the,chain,from,Item] &
- add [follow,the,chain,from,PreviousItem].
-
- rule dead_end forward
- if
- [follow,the,chain,from,Item] &
- [Item,is,ok] &
- -- the comes_from of Item is PreviousItem
- then
- announce ['Sorry, but ', Item, ' is as far back in the chain',nl,
- 'as I can go. I give up.'] &
- halt.
-
- rule ask_it forward
- if
- [follow,the,chain,from,Item] &
- -- [Item,is,ok] & /* not definitely ok... */
- -- [Item,is,kaput] /* not definitely kaput */
- then
- query ['Test ',Item,'in a known working circuit',nl,
- 'and then enter "ok." if it works,',nl,
- 'or "kaput." if it does not.']
- receives_answer Ans &
- add [Item,is,Ans].
-
- rule found_culprit forward
- if
- [Item,is,kaput]
- then
- announce ['OK: ',Item,' is your source of difficulty', nl,
- 'so you should replace it with a known working one.'] &
- halt.
-